package com.yjs.app.trade.web.controller.business;

import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.yjs.app.trade.core.util.DESUtils;
import com.yjs.app.trade.core.util.HttpUtils;
import com.yjs.app.trade.core.util.StringUtils;
import com.yjs.app.trade.entity.base.util.Page;
import com.yjs.app.trade.entity.bean.DispatchInvoice;
import com.yjs.app.trade.entity.bean.InvoiceProducter;
import com.yjs.app.trade.entity.bean.Products;
import com.yjs.app.trade.service.service.business.invoice.InvoiceService;
import com.yjs.app.trade.service.service.sys.InvoiceInfoCacheService;
import com.yjs.app.trade.service.service.sys.UserService;
import com.yjs.app.trade.web.controller.base.BaseController;
import com.yjs.app.trade.web.controller.base.util.Result;
import com.yjs.base.security.bean.UserContextManager;
import com.yjs.core.common.OperationResult;

import net.sf.json.JSONObject;

/**
 * 发票相关控制层
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/app/business/invoice")
public class InvoiceController extends BaseController {

	@Autowired
	InvoiceInfoCacheService infoCacheService;

	@Autowired
	InvoiceService invoiceService;
	
	@Autowired
	UserService userService;

	@Autowired
	UserContextManager userContextManager;

	/**
	 * 获取第三方发票数据并获取平台数据
	 * 
	 * @return
	 * @throws IOException
	 */
	public String fpjes;
	@RequestMapping(value = "/findThirdPartyInvoice", method = RequestMethod.GET)
	@ResponseBody
	public Object findThirdPartyInvoice(String data) throws IOException {
		JSONObject jsonObject=null;
		try {
			
			jsonObject = dpackData(data);
//			logger.info("-------------jsonObject:" + jsonObject);
		} catch (Exception e) {
			logger.error("-------------转json出错:data=" + data);
			
		}
		String invoiceInfo = jsonObject.getString("invoiceInfo");
//		logger.info("-------invoiceInfo:" + invoiceInfo);
		if (invoiceInfo != null && invoiceInfo != "") {
			String[] invoces = invoiceInfo.split(",");
			if(invoces.length<2){
				return Result.cfail("","扫描数据不完整请重新扫描");
			}
			String fphm=invoces[3];
//			logger.info("------------fphm:"+fphm);
			String fpdm=invoces[2];
//			logger.info("------------fpdm:"+fpdm);
			Map<String, Object> invoice = new HashMap<String, Object>();
			invoice.put("fpdm", fpdm);
			invoice.put("fphm", fphm);
			Map<String, Object> invoiceInfoCach = infoCacheService.getInvoiceInfoCach(invoice);
//			logger.info("-------根据发票号码和发票代码本地查询数据:");
			String kprq = invoces[5].substring(0, 4) + "-" + invoces[5].substring(4, 6) + "-" + invoces[5].substring(6);
			Map<String, Object> result = new HashMap<String, Object>();
			// 查询本地是否有缓存数据
			if (invoiceInfoCach != null &&  invoiceInfoCach.size()>=1) {
//				logger.info("-------本地有缓存invoiceInfoCach:"+invoiceInfoCach.toString());
				String resultByAli = (String) invoiceInfoCach.get("RESULT_CONTENT");
				result = resultUtill(invoces, kprq, result, resultByAli);
//				logger.info("-------返回值解析后的result" + result.toString());
				
			} else {
//				logger.info("-------本地没有缓存invoiceInfoCach=null");
				Map<String, String> body = new HashMap<String, String>();
				Map<String, String> param = new HashMap<String, String>();
				Map<String, String> header = new HashMap<String, String>();
				InetAddress address = InetAddress.getLocalHost();
				String hostAddress = address.getHostAddress();
				String datar = DESUtils.byte2String(DESUtils.encrypt(invoiceInfo, "yjs_trade_app"));
				// param.put("invoiceInfo", string);
				try {
//					logger.info("-------调用第三方接口");
					HttpResponse doGet = HttpUtils.doPost("http://" + hostAddress + ":18080",
							"/yjs_transaction/invoice/findInvoice?datar=" + datar, "POST", header, param, body);
//					logger.info("-------拿到值并返回");
					String str = EntityUtils.toString(doGet.getEntity());
//					logger.info("-------返回值:" + str);
					String resultByAli = DESUtils.getDecryptStr(str, "yjs_trade_app");
//					logger.info("----------resultByAli:" + resultByAli);
					Map<String, Object> ailiMap = new HashMap<>();
					ailiMap.put("number", invoces[3]);
					ailiMap.put("code", invoces[2]);
					ailiMap.put("resultContent", resultByAli);
//					logger.info("----------ailiMap:" + ailiMap.toString());
					infoCacheService.saveInvoiceCache(ailiMap);
					ailiMap.clear();
//					logger.info("-------返回值:" + resultByAli);
					result = resultUtill(invoces, kprq, result, resultByAli);
//					logger.info("-------返回值解析后的result" + result.toString());
					if(result.get("status")!=null){
						if(result.get("status").equals("006")){
							return Result.cfail("","查验不通过!");
						}else if(result.get("status").equals("015")){
							return Result.cfail("","不支持开具日期超过一年的发票查验!");
						}else{
							return Result.cfail("","查验错误!");
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			
			Map<String, Object> findPlatFormInovice = invoiceService.findPlatFormInovice(invoice);
			/*if (!StringUtils.equals((CharSequence) findPlatFormInovice.get("kprq"), "--")) {
				logger.info(findPlatFormInovice.toString() + "----------------------未添加前");
				findPlatFormInovice.put("fpje", fpjes);
				logger.info(findPlatFormInovice.toString() + "----------------------添加fpje" + fpjes);
				findPlatFormInovice.put("kprq", kprq);
				logger.info(findPlatFormInovice.toString() + "----------------------添加kprq" + kprq);
			}*/
			result.put("localInvoice", findPlatFormInovice);
			return Result.csuccess(result);
		}
		return Result.cfail("","扫描数据为空,请重新扫描!!");
	}

	/**
	 * 拿到阿里返回值进行解析
	 * 
	 * @param invoces
	 * @param fpjes
	 * @param kprq
	 * @param result
	 * @param resultByAli
	 * @return
	 */
	private Map<String, Object> resultUtill(String[] invoces, String kprq, Map<String, Object> result,
			String resultByAli) {
		JSONObject fromObject = JSONObject.fromObject(JSONObject.fromObject(resultByAli).get("data"));
//		logger.info("----------WEB的fromObject:" + fromObject);

		if (fromObject.get("status").equals("001")) {
			@SuppressWarnings("unchecked")
			Map<String, Object> parse = (Map<String, Object>) JSON
					.parse(net.sf.json.JSONObject.fromObject(resultByAli).getString("data"));
			@SuppressWarnings("unchecked")
			Map<String, Object> pareser = (Map<String, Object>) parse.get("data");
			fpjes = (String) pareser.get("jshj");
//			logger.info("-------parse:" + parse);
			Map<String, Object> aliresult = new HashMap<String, Object>();
			aliresult.put("shuie", pareser.get("se"));
			aliresult.put("kprq", kprq);
			aliresult.put("fphm", invoces[3]);
			aliresult.put("fpdm", invoces[2]);
			aliresult.put("jshj", pareser.get("jshj"));// 需要更改
			aliresult.put("je", pareser.get("je"));
			aliresult.put("gfmc", pareser.get("gfmc"));
			aliresult.put("xfmc", pareser.get("xfmc"));
			result.put("aliInvoice", aliresult);
		} else if (fromObject.get("status").equals("006") || fromObject.get("status").equals("009")) {
			result.put("status", "006");
			
		} else if (fromObject.get("status").equals("015")) {
			result.put("status", "015");
		} else {
			result.put("status", "000");
		}
		return result;
	}

	/**
	 * 通过比对第三方扫码获取的发票数据和平台发票数据 ,如果数据一致，则确认收票
	 * 
	 * @return
	 */
	@RequestMapping(value = "/confirmTheReceiptOfInvoice", method = RequestMethod.GET)
	@ResponseBody
	public Object confirmTheReceiptOfInvoice(String data, HttpServletRequest request) {
		JSONObject dpackData = dpackData(data);
		String invoiceInfoId = (String) dpackData.get("invoiceInfoId");
		String token = request.getHeader(userToken);
		if (token != "" && token != null) {
			String retoken = token.replace("org.user.context.a", "a");
			userContextManager.set(retoken);
			OperationResult result = invoiceService.confirmTheReceiptOfInvoice(invoiceInfoId);
			if (result.getResultCode() == 1) {
				return Result.csuccess();
			} else {
				return Result.cfail("", result.getResultMessage());
			}
		}
		return Result.cfail("","token=" + token);

	}

	/**
	 * 通过比对第三方扫码获取的发票数据和平台发票数据 ,如果数据不一致，则拒绝收票
	 * 
	 * @param request
	 * @param data
	 * @return refuseReason:拒绝理由
	 */
	@RequestMapping(value = "/rejectInvoice", method = RequestMethod.GET)
	@ResponseBody
	public Object rejectInvoice(HttpServletRequest request, String data) {
		JSONObject dpackData = dpackData(data);
		String invoiceInfoId = (String) dpackData.get("invoiceInfoId");
		String refuseReason = (String) dpackData.get("refuseReason");
//		logger.info("---------refuseReason=" + refuseReason.toString());
		// String token = userAuthorityService.appLogin("zbb0717a", "123456",
		// "1");
		String token = request.getHeader(userToken);
		if (token != "" && token != null) {
			String retoken = token.replace("org.user.context.", "");
			userContextManager.set(retoken);
			OperationResult rejectInvoice = invoiceService.rejectInvoice(invoiceInfoId, refuseReason);
			if (rejectInvoice.getResultCode() == 1) {
				return Result.csuccess();
			} else {
				return Result.cfail("", rejectInvoice.getResultMessage());
			}
		}
		return Result.cfail("","token=" + token);
	}

	@RequestMapping(value = "/findInvoice", method = RequestMethod.GET)
	@ResponseBody
	public Object findInvoice(HttpServletRequest request, Page<DispatchInvoice> page, DispatchInvoice dispatchInvoice, String data) {
		//logger.info("进入发票查询接口--------"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
		JSONObject jsonObject = dpackData(data);
		//String type=jsonObject.getString("invoiceType");
		page.setPageNo(jsonObject.getInt("pageNo"));
		if (jsonObject.get("pageSize") != null) {
			page.setPageSize(jsonObject.getInt("pageSize"));
		}
		if (jsonObject.get("invoiceNum") != null) {
			dispatchInvoice.setInvoiceNum(jsonObject.getString("invoiceNum"));
		}
		if (jsonObject.get("invoiceCode") != null) {
			dispatchInvoice.setInvoiceCode(jsonObject.getString("invoiceCode"));
		}
		if (jsonObject.get("beginDt") != null) {
			dispatchInvoice.setBeginDt(jsonObject.getString("beginDt"));
		}
		if (jsonObject.get("endDt") != null) {
			dispatchInvoice.setEndDt(jsonObject.getString("endDt"));
		}
		
		if (jsonObject.get("rebeginDt") != null) {
			dispatchInvoice.setRebeginDt(jsonObject.getString("rebeginDt"));
		}
		if (jsonObject.get("reendDt") != null) {
			dispatchInvoice.setReendDt(jsonObject.getString("reendDt"));
		}
		
		if (jsonObject.get("fund") != null) {
			dispatchInvoice.setFund(jsonObject.getString("fund"));
		}
		if (jsonObject.get("confirmMember") != null) {
			dispatchInvoice.setConfirmMember(jsonObject.getString("confirmMember"));
		}
		if (jsonObject.get("state") != null) {
			dispatchInvoice.setState(jsonObject.getString("state"));
		}
		if (jsonObject.get("invoiceType") != null) {
			dispatchInvoice.setInvoiceType(jsonObject.getString("invoiceType"));
		}
		List<Map<String, Object>> passportsMap = userService.getPassportSalesAut(getUserId(request));
		if (StringUtils.strIsNull(passportsMap.get(0).get("adminPassportId"))) {
			List<String> memberIds = new ArrayList<>();
			for (Map<String, Object> map : passportsMap) {
				if (map.get("memberId") != null) {
					memberIds.add(map.get("memberId").toString());
				}
			}
			if (memberIds != null && memberIds.size() > 0) {
				dispatchInvoice.setMemberIds(memberIds);
			} else {
				return Result.csuccess(page);
			}
		}
		if (jsonObject.get("sort") != null) {
			dispatchInvoice.setSort(jsonObject.getString("sort"));
		}else{
			dispatchInvoice.setSort("DESC");
		}
		dispatchInvoice.setDispatcherId(getUserMemberId(request));
		//logger.info("查询数据--------"+new SimpleDateFormat("HH:mm:ss").format(new Date())+" : "+dispatchInvoice.getMemberIds().toString());
		Page<?> findInvoice = invoiceService.findInvoice(page, dispatchInvoice);
		//logger.info("发票完成返回--------"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
		return Result.csuccess(findInvoice);
	}
	
	/**
	 * 测试专用
	 */
	@RequestMapping(value = "/findInvoicet", method = RequestMethod.GET)
	@ResponseBody
	public Object findInvoicet(HttpServletRequest request, Page<DispatchInvoice> page, DispatchInvoice dispatchInvoice, String data) {
		return "0af6668c894691598d6ee21e8d99d1b91c8bbfabea3b54aa179115fa529e80d2e7bdddf8c64aa37d3473d64e211bb7425e35954cb9ebccd397f5d61764427b9910fe3973bacda8bb013baf344f913b49deca5cb16a36a21e62768b07b539df2b0b530aaec2ad5d2dc9e8923fb5d5e0fe2d18cd81f8b51ea6363b25b231976bdb6e550094576d366eb623b315c28e5ab1e0384ab1093c50fe028167d6c30d897f47bc333ebe8fe8d00cb8aa90b4bebb02d4639b63c0b7a2bdbda71fedc490d10950b3093bf6fb85a159a0a3127e393c28306b60f343d39e6b04738376d0b8c7990793b9575be8104b2855e8a5b3eea40a0f6c3c71a70f96b69b7771ad240a8a12ef1c2f15fab8bfb1c72cd98f8c5882c7f3725262610b750adac0d70af3c2a8d3de191d569e0462c1f121645a114e66426481ca9c6229b8d0dd313ce6865e17b2770ba3f9a6b142d7dfebe632e1d8741fca567216843014598895702758cb29a03482821d1c5401417a0ecf872052ebbf07742c5c810922b49cf132fbf1dda6d3b789e1258c70460c22e6ad8161f2e72241722caeb1cf62ab007068f196ac61899404e375157c7bc79b7771ad240a8a12dfabc8e304bc47b9ad5adb14fd98a926c2184e6324a719f895e5e7428d0e7b046c2970500394a53c0baf637c6776798751a66a0fe136100abf972e0689c1f4d779fe9379c0184cecf44fd03c13b0ff0f77d403f654e2ae02f7eb05b07af8f2a84cb541c52f79f32aa7563879ff13d41f559bb5181c4d20295a193c60da0411565f52f95dd53834d7f8c2379c1ce9483765ef47ed429088a0de0674c958d57f3d38e0c98ddaed0d5cf73db4e886c89f595923996103876d498505470c935a7d73f8a6835e0ed598743482821d1c5401417088c2ed5cc1fc70d45be34bab703954c9669650642960af0d6b16a55727667bd5a0e8f64b73186b7ae16eef891699d2d24dbbbfd6c7583f39c71401f3a9fc7310bbfdf8ddce8d53f7f3a5fd10465f2bbd84e272cbe617c20bf36d682327b22861f75a46b5a99d564f58430232524699e4e05c98474297edfc2d71e1c4b2e9a733b82b0988ca5b0a0d417607786d2faf1d81a7eebfd07e684015ed742610aab006f2068ba9932433d3421a9d5eb9f8dba79e23ee994c737eb1377cd5a3afa812784d4b975c7a808cfa0f00b13fd6808b2e29a0a0ce2a8885b2cc1e619c77db1f9499b8d2de4bb539b21816b6faed9f7e048b7a21f52533de6f425d0ea9bfa6a68362fa94be17662504738376d0b8c7998cc79d0cc55353853592c674812b5466cc8a9a780178bcfec4f2b82a71ce1fa66dd45378e6e9007b50b3093bf6fb85a1773e30f0cc9c22439025e318d47ddcce8eaf677acab8bed2d7c9bf8d48f653175da343c7b2e4157029bb3d432f2001f0ccc9fd3f8d39874fd3421a9d5eb9f8db44747ca6c578278fd81207a1b03e5443a61f97992b837dc24b229d65015f7af895e3eace832e1ca7f883b854a0aa636b0bf36d682327b22861f75a46b5a99d564f58430232524699e4e05c98474297ede4a741089310a55133b82b0988ca5b0a0d417607786d2faf1d81a7eebfd07e684015ed742610aab006f2068ba9932433d3421a9d5eb9f8dba79e23ee994c737eb1377cd5a3afa812b74789912c00385f1f283c4386beca20a6136644b043608521f4286e42848544d0022bba42f75d74071ff64ce6c912eb5f3a01e7b1b2a21bb06278b1ba5606070d417607786d2faf344536d31aae1871018a5a11e69e06a9e4e05c98474297ed2de5274ead1c29788c7666697781666a560f3be1c5318c70e73d15f2637a279bd638ed33316b1440a219524c9f4fbc0bff5856952b19341d31f18d13564c1fc78674c60a06fb6220de3f6d560b673a95d50702d7283d4946b22bf73aeea047d96216a14d781a7e014edb4c28d107bbafad5adb14fd98a926c2184e6324a719f895e5e7428d0e7b046c2970500394a53c9b6cfe505191bd2751a66a0fe136100abf972e0689c1f4d779fe9379c0184cecf44fd03c13b0ff0f77d403f654e2ae02f7eb05b07af8f2a84cb541c52f79f32aa7563879ff13d41f0f47d2188c92c1c2dc1af8a41d91d60d30ed0aff67b11d7e407ea64859fe6930e045c84794961deb9d49fcefebd236c2a8e54202e39d5dcbbaf2b5517c5a71e34d1e689d882fbeaecef6b7493690f4ddfa02ad984bec2acfe3f092665d7107d71f60574308872e988c7666697781666a560f3be1c5318c70e73d15f2637a279bd638ed33316b1440a219524c9f4fbc0bff5856952b19341d31f18d13564c1fc78674c60a06fb6220de3f6d560b673a95d50702d7283d4946b22bf73aeea047d96216a14d781a7e014edb4c28d107bbafad5adb14fd98a926c2184e6324a719f895e5e7428d0e7b046c2970500394a53c81ee5b3009f3dd2b93781ca006b91d63bf972e0689c1f4d779fe9379c0184cecf44fd03c13b0ff0f77d403f654e2ae02f7eb05b07af8f2a84cb541c52f79f32aa7563879ff13d41f9d12a1db8690a028dc1af8a41d91d60d30ed0aff67b11d7e4c1d6a11fcef29d9e045c84794961deb7ca154d6abe51d655291688c211487d11aad84b936e535b9b330d3ac62aa8c5e14deb73d4f9a8235566a0ae558fc5576ba23dabc0e41b2efcb42b2bfa6bb34969bbc259640ddc630e3f092665d7107d7c48b6580ee9c4d3cb75572e289c736c439093f7b7aaa1a719b8674e825f09ba1d484bb57eb70203721f6f0369f4da79a4bed79b71fe1fb4290eb2cbd2b9a525aa90dc6a2707cb58dc4d1267802c1bc7c1093bdc67bde6ed9bf5ba769cbd0eec86e364011ab95b5f3e8aa38ec9693004a0fa712ca4604f5946bd3ac5adece0df61583d7edc416023340a8945314281ec8bc562389cf5407fdef3fa059971b73a970997bfd69d21e5bc5c10b0c8c75a9e09a3fe2d51d4378dcd21548bf055acbfb45785eb2faa8cc358ccf081fe3be5d285f52f95dd53834d7256872ed088052c565ef47ed429088a05533d05a8ddcc86738e0c98ddaed0d5cf73db4e886c89f595923996103876d498505470c935a7d734e72ffa732f8407f3c64f708d12d19c67248894e1eef0e89d6666cb6ded58e08636e67d1302b66c5d24dbbbfd6c7583f39c71401f3a9fc7310bbfdf8ddce8d53f7f3a5fd10465f2bbd84e272cbe617c2490c6bf707a56a016e24ba3b835f43f86a51f09326fbc51c7e6a338ff5bd944ed5e951e7d648a05fa73a3c1167211752c9710eb69fbf6a9a5a24c176b1569e0551c562b68633302b9a1e070a0da155b159733ef3ca44df722ed72906e37ac30534d6b23f03ede50cbc57613f397cb1b6d1e443eff7a22e56860bbd991c413a4a33ef42337d71a6e99490d896885ccabd03d47668f3181a5a771ed73c59ecea6b21512af49eb05b08b8c880b76c106d99763ff9e6c17fcbf26f425d0ea9bfa6a68362fa94be176625de0cd02ccbcc30436d32006f22b7cdc7d0f619e4af9c2462b04c357b73f3cd8f8ee6c93e1491fba183daa761feb96a0e586af86b44bab7ee6d2c378ea61aab2a9cf132fbf1dda6d3b789e1258c70460c22e6ad8161f2e72241722caeb1cf62ab007068f196ac61899404e375157c7bc79b7771ad240a8a12dfabc8e304bc47b9ef1c2f15fab8bfb11e8f316fca9285bff53755e6fdbd61616a06b76f160e1f823652f256d6f9906186a0734174942d8ad4639b63c0b7a2bdbda71fedc490d10950b3093bf6fb85a1b84ba65af4b58b5e306b60f343d39e6b04738376d0b8c7990793b9575be8104b2855e8a5b3eea40a0f6c3c71a70f96b69b7771ad240a8a12ef1c2f15fab8bfb138d0692de93aad716a4fa92837def02ab621b067e7fc4a3022f7bfbc1e80826fb563ed62e3dc02fecd511aa950570118b25d868d2ef7eba47c7e8cab905964845798ddc9890d377253f068d73094ebf612a8b6cc59a354f044fdd5c5dcd5032fc12012db4ce66d033c9c77888a96ace6b75572e289c736c439093f7b7aaa1a713d0ed1c7f13e0f9f5e8621e9bb46f6a3663002551d544fd91de38ee9a22c6dd6281613bf7310592b53008ac9efb5d1ff3b2116d1ed803099a750a900c2b3856a5703648cce149e3c9912626060f34816c4c3e38941f219d44b5b5df56b3cf5c3421927f6db4eb34467575a075a3564d6194bec52861f2659586af86b44bab7eebfd787a935d9101296516e6ded94b94e3db5126b6a233a2664852acfd92a2b1cc004f8578e9c248e73c6246f1030cd601cdca43bf1d6a47e490c6bf707a56a01790663c135866e9d6ba28fd48513c62e2e29a0a0ce2a8885a79786bf3f495a279499b8d2de4bb5399c344b4c404a2449ca2cb70cde8e214b6f425d0ea9bfa6a68362fa94be176625de0cd02ccbcc3043bdbe35336ce90b3b646ae84a31703f9b77eb7ea2cca570bc3dbacdb4e375e5eb3482821d1c540141fc1dcc79004e1792d1d4d6c1299dd3aacbf1d45f2d6d838bdfabb4b31cb08b336e0e858e79d4769e663002551d544fd91de38ee9a22c6dd6281613bf7310592b53008ac9efb5d1ff3b2116d1ed803099a750a900c2b3856a5703648cce149e3c9912626060f3481615d529c80d24c5c6fa88328993bcf60640be3930d084b42689df7da698367570b9920bdddb723346175a45b083cae222b003ed4a2d90c60833bfca62785403af101d43550d495eda52d7831c97590ba0e4b6ec14e64c578e8aa325997cc874a227ca6cd42a16100d7cb3f38ded801ad5ad7fac3ef64cc8562f52c22acf9f743ca9057a62cc3d01a491ed1f8161611808d274cca4cb169c346567bfbe9a00ea2b";
	}
	
	
	@RequestMapping(value = "/findInvoiceInformation", method = RequestMethod.GET)
	@ResponseBody
	public Object findInvoiceInformation(String data) {
		JSONObject jsonObject = dpackData(data);
		String invoiceInfoId=jsonObject.getString("invoiceInfoId");
		InvoiceProducter invoiceProducter=new InvoiceProducter();
		Products product=new Products();
		List<Map<String,Object>> products=invoiceService.findProductByInvoice(invoiceInfoId);
		List<Products> orders = new ArrayList<>();
		boolean flag = true;
		List<Map<String,Object>> listtt = new ArrayList<>();
		for (Map<String, Object> map : products) {
			flag = true;
			if(orders!=null && orders.size()!=0){
				for (Products p : orders) {
					if(p.getOrderNum().equals(map.get("ORDER_NO"))){
						product.getProducts().add(map);
						flag = false;
					}
				}
			}
			if (flag) {
				product = new Products();
				product.setDate((String) map.get("CREATED"));
				product.setOrderNum((String) map.get("ORDER_NO"));
				listtt = new ArrayList<>();
				listtt.add(map);
				product.setProducts(listtt);
				orders.add(product);
			}
		}
		Map<String,Object> num=invoiceService.findInvoiceNum(invoiceInfoId);
		invoiceProducter.setOrders(orders);
		invoiceProducter.setNumber(num);
		return Result.csuccess(invoiceProducter);
	}

}
